package thread;

public class ExclusiveVariable {
    public static void main(String[] args) {
        Task task = new Task();
        for (int i = 0; i < 3; i++) {
            Thread t = new Thread(task);
            t.start();
        }
    }
}

class Task implements Runnable {
    private static ThreadLocal<Integer> tl = ThreadLocal.withInitial(() -> 0);

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            Integer j = tl.get();
            j++;
            tl.set(j);
            System.out.println(j);
        }
    }
}
